package com.krain.ddbb.activity;

import android.content.Intent;
import android.text.TextUtils;
import android.widget.EditText;

import com.krain.corelibrary.widget.loadingView.LoadingView;
import com.krain.ddbb.R;
import com.krain.ddbb.base.BaseActivity;
import com.krain.ddbb.entity.AppApi;
import com.krain.ddbb.entity.BaseEntity;

import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

/**
 * Created by ex-kuangxiaomin101 on 2016-01-27.
 */
@EActivity(R.layout.activity_add_addres)
public class AddAddresActivity extends BaseActivity {

    @ViewById(R.id.act_addres_et)
    EditText mEtAddres;


    /**
     * 添加用户地址
     */
    @Click(R.id.act_address_btn_add)
    void onClickAddAddres() {
        if (TextUtils.isEmpty(mEtAddres.getText().toString())){
            baseUtil.showSnackBar(mContext,"请填写正确的地址");
            return;
        }
        postAddres();
    }

    @Background
    void postAddres(){
        showProgressDialog();
        BaseEntity entity = AppApi.getsInstance(mContext).postAddress(app.getmUserinfo().getAccess_token(),mEtAddres.getText().toString());
        if(entity!=null){
            baseUtil.showSnackBar(this, "用户地址添加成功！");
            setResult(RESULT_OK);
            finish();
            }
        dismissProgressDialog();
    }

    public static void jumpTothisActivity(BaseActivity activity) {
        Intent intent = new Intent(activity, AddAddresActivity_.class);
        activity.startActivityForResult(intent,0);
    }

    @Override
    protected String getToolbarTitle() {
        return "添加地址";
    }


}
